<!--
	作者：956911785@qq.com
	时间：2019年11月21日22:15:53
	描述：账号或密码修改-添加
-->

<template>
	<Modal title="账号或密码修改" v-model="modal0" width="400px">
		<Form ref="params" :model="params" :rules="ruleValidate" :label-width="100" label-position="left">
			<div style="width:100%;height:180px; overflow-y: hidden;">
	        	<div style="width: 100%;text-align: left;float: left;height: 60px;line-height: 60px;" align="left">
			        <FormItem  prop="dlzh" label="账号">
			        	<Input v-model="params.dlzh" placeholder="请输入账号！" clearable style="width: 70%" ></Input>
	        		</FormItem>
	        	</div>
	        	<div style="width: 100%;text-align: left;float: left;height: 60px;line-height: 60px;" align="left">
			        <FormItem  prop="odlma" label="旧密码">
			        	<Input type="password" v-model="params.odlma" placeholder="请输入旧密码！" clearable style="width: 70%"></Input>
	        		</FormItem>
	        	</div>
	        	<div style="width: 100%;text-align: left;float: left;height: 60px;line-height: 60px;" align="left">
			        <FormItem  prop="dlma" label="新密码">
			        	<Input type="password" v-model="params.dlma" placeholder="请输入新密码！" clearable style="width: 70%"></Input>
	        		</FormItem>
	        	</div>
		   </div> 
	    </Form>
	   	<div slot="footer">
	    	<Button type="text"  @click="closeModal()">取消</Button>
	    	<Button type="primary" @click="updateUaccount()" >确定</Button>
	    </div>
     </Modal>
</template>

<script>
	export default {
		name:"tconent",
		props: {
    		usrs:{
    			type:Object,	
    			default: function() {
					return null
				}
    		},
    	},
		data() {
			//长度控制
			const lenPass = (rule, str, callback) => {
			  if(str.length>rule.length){
			  	 callback(new Error('字符串长度在1-'+rule.length+'之间！'));
			  }
			  return callback();
			};
			return {
				params:{
					olddlzh:'',
					dlzh:'',
					dlma:'',
					odlma:''
				},
				modal0:false,
				ruleValidate: {
					dlzh: [
		                {required: true, message: '请输入账号！', trigger: 'blur'},
		                {length:20,validator:lenPass,trigger:'blur'}
		            ],
		            odlma: [
		                {required: true, message: '请输入旧密码！', trigger: 'blur'},
		                {length:20,validator:lenPass,trigger:'blur'}
		            ],
		            dlma: [
		                {required: true, message: '请输入新密码！', trigger: 'blur'},
		                {length:20,validator:lenPass,trigger:'blur'}
		            ],
				}
			}
		},
		components: {
		},
		methods: {
			closeModal(){
				this.modal0= false;
			},
			updateUaccount(){
				if(this.params.odlma!=this.usrs.dlma){
					this.$Modal.error({
					    title: "提示",
					    content: "旧密码错误，请重新输入！"
					});	
					return;
				}
				this.$refs.params.validate((valid) => {
					if (valid){
						//保存
						this.$http.post("/host/readbook/uaccount/updateUaccount.html",this.params)
						.then(datas => {
							//添加成功 刷新页面
							if(datas.result){
								this.$Modal.success({
		                            title: "成功",
		                            content: "修改成功！",
		                            onOk: () => {
		                            	this.modal0= false;
		                            	this.$router.push({
											path: '/login'
										});
		                            }
		                       });
							}else{
								this.$Modal.error({
		                            title: "失败",
		                            content: datas.msg
		                        });	
							}
						});
                    }
               })
			}
		},
		computed: {
		},
		mounted() {
		
  			
		},
		watch:{
			modal0(news,olds){
				if(news){
					this.params.olddlzh=this.usrs.dlzh;
					this.params.dlzh=this.usrs.dlzh;
				}
			}
		},
	}
</script>

<style scoped="scoped">
	
</style>



